import {getWy,getPlatform} from '@/uni_modules/wy-core/context';
function _resList(result){  //结果包装
    let {ret,msg,data}=result
    result={
        code:ret>=200?0:1,
        data,
        msg,
        ret
    } 
    return  result
};
function _resModel(result){  //结果包装
     let {ret,msg,data}=result
    result={
        code:ret>=200?0:1,
        data,
        msg,
        ret
    } 
    return  result
};
function _resData(result){  //结果包装
     let {ret,msg,data}=result
    result={
        code:ret>=200?0:1,
        data,
        msg,
        ret
    } 
    return  data
};
function _resAction(result){  //结果包装
    let {ret,data,msg}=result
    let {status,tip}=data
    result={
        code:ret>=200?0:1,//status==1?0:1,
        msg:tip?tip:msg, 
        data:data,
        ret
    }
    return result
};
function getData(ac,option,_params={}){
    let {params,method,header}=option
    header=header?header:{}
    method:method?method:'POST'
    let obj={
        data:{},
        params:{
            ac,
            ...params,
            ..._params
        },  
        method,
        header,
        res:util._resData,
        option
    }  
    return getWy().request(obj) 
};
function getModel(ac,option,_params={}){
    let {params,data={},method,header}=option
    header=header?header:{}
    method:method?method:'POST'
    let obj={
        data,
        params:{
            ac,
            ...params,
            ..._params
        },  
        method,
        header,
        res:util._resModel,
        option
    }  
    return getWy().request(obj)  
};
function getList(ac,option,_params={}){
    let {params,data={},method,header}=option
    header=header?header:{}
    method:method?method:'POST'
    let obj={
        data,
        params:{
            ac,
            ...params,
            ..._params
        }, 
        method,
        header,
        res:util._resList,
        option
    } 
    return getWy().request(obj)  
};
function doAction(ac,option,_data={},_params={}){
    let {params,data,method,header}=option
    header=header?header:{}
    method:method?method:'POST'
    let obj={
        data:{
            ...data,
            ..._data
        },
        params:{
            ac,
            ...params,
            ..._params
        }, 
        method,
        header,
        res:util._resAction,
        option
    } 
    return getWy().request(obj)  
};
export  {
    _resList,
    _resModel,
    _resData,
    _resAction,
    getData, 
    getModel,
    getList,
    doAction
}  